<script setup lang="ts">
import { ref, nextTick } from "vue";
import TrackListTable from "./TrackListTable.vue";
import ParkListTable from "./ParkListTable.vue";
import CityListTable from "./CityListTable.vue";
import { DownSvg } from "../images/index";

// 定义信息数据接口
const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  },
  panelConfig: {
    type: Object,
    default: () => ({})
  }
});

// 辅助函数，判断module是否显示
const shouldShowField = (field: keyof typeof props.panelConfig) => {
  return props.panelConfig[field] !== false; // 默认显示，除非明确设置为false
};

// 定义组件Emits
const emit = defineEmits<{
  (e: "visibleChange", value: boolean): void;
}>();

// 控制面板显示状态
const visible = ref(false);
// 当前激活的标签页(1:位置明细, 2:停留点, 3:途径城市)
const active = ref("1");

// 打开面板方法
const open = () => {
  visible.value = true;
  emit("visibleChange", true);

  // 确保选中第一个可见的标签页
  nextTick(() => {
    if (shouldShowField("trackList")) {
      active.value = "1";
    } else if (shouldShowField("parkList")) {
      active.value = "2";
    } else if (shouldShowField("cityList")) {
      active.value = "3";
    }
  });
};

// 关闭面板方法
const handleClose = () => {
  visible.value = false;
  emit("visibleChange", false);
};

// 轨迹表格组件引用
const trackListTable = ref();
const parkListTable = ref();
const cityListTable = ref();

const init = () => {
  nextTick(() => {
    trackListTable.value?.init();
    parkListTable.value?.init();
    cityListTable.value?.init();
  });
};

// 开启滚动
const start = (radio: number) => {
  if (active.value === "1" && trackListTable.value) {
    trackListTable.value.start(radio);
  }
};

// 暂停滚动
const pause = () => {
  if (active.value === "1" && trackListTable.value) {
    trackListTable.value.pause();
  }
};

// 关闭滚动
const stop = () => {
  if (active.value === "1" && trackListTable.value) {
    trackListTable.value.reset();
  }
};
defineExpose({
  open,
  handleClose,
  start,
  pause,
  stop,
  init
});
</script>

<template>
  <!-- 面板显示过渡动画 -->
  <transition name="slide-up">
    <!-- 主容器 -->
    <div class="info-wrapper" v-show="visible">
      <!-- 关闭按钮 -->
      <DownSvg class="upIcon" @click="handleClose"></DownSvg>
      <!-- 内容区域 -->
      <div class="info-container">
        <!-- 标签页组件 -->
        <el-tabs v-model="active">
          <!-- 位置明细标签页 -->
          <el-tab-pane v-if="shouldShowField('trackList')" label="位置明细" name="1">
            <TrackListTable ref="trackListTable" :list="info?.trackList" :type="info?.dockingChannels"></TrackListTable>
          </el-tab-pane>
          <!-- 停留点标签页 -->
          <el-tab-pane v-if="shouldShowField('parkList')" label="停留点" name="2">
            <ParkListTable ref="parkListTable" :list="info?.parkList" :type="info?.dockingChannels"></ParkListTable>
          </el-tab-pane>
          <!-- 途径城市标签页 -->
          <el-tab-pane v-if="shouldShowField('cityList')" label="途径城市" name="3">
            <CityListTable ref="cityListTable" :list="info?.cityList"></CityListTable>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </transition>
</template>

<style lang="scss" scoped>
/* 面板显示/隐藏的过渡动画 */
.slide-up-enter-active,
.slide-up-leave-active {
  transition: all 0.3s ease;
}
.slide-up-enter,
.slide-up-leave-to {
  opacity: 0;
  transform: translateY(10px);
}

/* 主容器样式 */
.info-wrapper {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(100% - 22px);
  height: 340px;
  background: #ffffff; // 白色背景
  border-radius: 4px; // 圆角边框
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%); // 外部阴影效果
}

/* 关闭按钮样式 */
.upIcon {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 1500;
  width: 40px;
  height: 40px;
  cursor: pointer;
  transform: translateX(-50%);
  animation: wave 2s ease-in-out infinite; // 波浪动画效果
}

/* 波浪动画关键帧 */
@keyframes wave {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  25% {
    transform: translateX(-50%) translateY(-5px);
  }
  50% {
    transform: translateX(-50%) translateY(0);
  }
  75% {
    transform: translateX(-50%) translateY(-10px);
  }
}

/* 内容区域样式 */
.info-container {
  width: calc(100% - 20px);
  height: calc(100% - 40px);
  padding: 0 10px;
  margin-top: 40px;
  background-color: #ffffff;
  border-radius: 0 0 4px 4px; // 底部圆角
  box-shadow: inset 0 0 10px rgb(0 0 0 / 5%); // 内阴影效果
  :deep(.el-tabs__header) {
    margin-bottom: 5px !important;
  }
}
</style>
